package com.chen.authority.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.chen.authority.common.annotation.Log;
import com.chen.authority.common.enums.BusinessType;
import com.chen.authority.common.response.MultiResponse;
import com.chen.authority.common.response.Response;
import com.chen.authority.model.vo.OnlineUserVo;
import com.chen.authority.service.OnlineUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 在线用户监控
 *
 * @author chengy
 * @date 2022/11/19
 */
@Api(tags = "在线用户监控 OnlineUserController")
@RequiredArgsConstructor
@RestController
@RequestMapping("/monitor/online-user")
public class OnlineUserController {

    private final OnlineUserService onlineUserService;

    @GetMapping
    @ApiOperation("获取在线用户列表")
    @SaCheckPermission("monitor:online-user:list")
    public MultiResponse<OnlineUserVo> list(String username, String name) {
        return onlineUserService.findOnlineUserList(username, name);
    }

    @ApiOperation("强退用户")
    @SaCheckPermission("monitor:online-user:force")
    @DeleteMapping("/{id}")
    @Log(module = "系统监控-在线用户", businessType = BusinessType.FORCE)
    public Response forceLogout(@PathVariable Integer id) {
        StpUtil.kickout(id);
        return Response.success();
    }

}
